<template>
	<view>
		<view class="classification">
			<view class="center" :class="{'center-select':navbar.select.is_end == i.is_end}" v-for="i,j in navbar.list"
				:key="i.is_end" @tap="change_navbar_select(i)">
				<view class="top">
					{{i.val}}
				</view>
				<view class="bottom">

				</view>
			</view>

			<!-- 			<view class="center">
				<view class="top">
					已完成
				</view>
				<view class="bottom">

				</view>
			</view> -->
		</view>
		<view class="user-box">
			<view class="user" v-for="i,j in activities.list" :key="j">
				<view class="head">
					<view class="left">
						<image class="left" :src="i.headImage" mode=""></image>
						<text class="right">{{i.nickname}}</text>
					</view>
					<view class="right" @tap="go_submit_list(i.id,i.is_end)">
						查看提交
					</view>
				</view>
				<view class="content">
					{{i.content}}
				</view>
				<view class="image">
					<image class="center" v-for="i1,j1 in i.activitiesImage" :key="j1" :src="i1" mode=""></image>
				</view>
				<view class="dot">
					<image class="right" :src="$img('/static/2021-08-25/dot.png')" mode=""></image>
				</view>
			</view>
		</view>

		<view class="no-more-box">
			<view class="no-more-line">

			</view>
			<view class="no-more-text">
				没有更多了
			</view>
			<view class="no-more-line">

			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				navbar: {
					list: [{
							is_end: 0,
							val: "发布中"
						},
						{
							is_end: 1,
							val: "已完成"
						}
					],
					select: {
						is_end: 0,
						val: "发布中"
					}
				},
				activities: {
					list: null,
					page: 1
				}
			}
		},
		onLoad() {
			// this.get_data(1);
		},
		onShow(){
			this.get_data(1);
		},
		onReachBottom() {
			this.get_data();
		},
		watch: {
			navbar: {
				handler(now) {
					this.get_data(true);
				},
				deep: true
			}
		},
		methods: {
			go_submit_list(id,is_end) {
				uni.navigateTo({
					url: "/pages/my/submit-list/submit-list?id=" + id + "&is_end="+is_end
				})
			},
			// 获取我的活动列表
			get_data(reset) {
				if (reset) {
					let activities = this.activities;
					activities.page = 1;
					activities.list = [];
					this.activities = activities;
				}
				if (this.activities.page == -1) {
					return
				}
				let data = {
					is_end: this.navbar.select.is_end,
					page: this.activities.page
				}
				this.$utils.postrequest('/api/activit_signup/index', data, (res) => {
					
					res.data.map(item => {
						item.headImage = JSON.parse(item.avatar)[0];
						item.activitiesImage = JSON.parse(item.image);
						
					})
					this.activities.list = [...this.activities.list, ...res.data];
					this.activities.page++
					if (res.data.length < 1) {
						this.activities.page = -1;
					}
				})
			},
			change_navbar_select(item) {
				this.navbar.select = item;
			}
		}
	}
</script>

<style scoped lang="scss">
	@import "./my-activities.scss";
</style>
